﻿#include "maindesktop.h"
#include "ui_maindesktop.h"
#define ASMORDERDBSTR ConnectPoolFactory::getInstance()->getConnectPool(ConnectPoolFactory::AsmOrderDataBase)

MainDesktop::MainDesktop(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainDesktop)
{
    ui->setupUi(this);
    MainDesktopInit();

    DesktopTimer = new QTimer(this);
    connect(DesktopTimer,&QTimer::timeout,this,&MainDesktop::ON_MainDesktopTimer);
    DesktopTimer->start(300);

}

MainDesktop::~MainDesktop()
{
    delete ui;
}

void MainDesktop::MainDesktopInit()
{
    /**
     * 赖俊龙
     * 日志显示替换掉监控显示
     */
//    monitoringI = new monitoring;
//    ui->stackedWidget->insertWidget(0,monitoringI);
//    ui->stackedWidget->widget(0)->layout()->setContentsMargins(0,0,0,0);
//    ui->stackedWidget->setCurrentIndex(0);

    dailyRecordI = new dailyRecord;
    ui->stackedWidget->insertWidget(0,dailyRecordI);
    ui->stackedWidget->widget(0)->layout()->setContentsMargins(0,0,0,0);
    ui->stackedWidget->setCurrentIndex(0);
    connect(dailyRecordI,&dailyRecord::sig_WriteModbusI,this,&MainDesktop::ON_WriteModbusI);
    connect(dailyRecordI,&dailyRecord::sig_UpdateStation,this,&MainDesktop::ON_UpdateStation);
    connect(this,&MainDesktop::sig_Translate,dailyRecordI,&dailyRecord::ON_Translate);


    table_single::GetInstance()->TableWidgetInit(ui->tableWidget,14,"QHeaderView::section{background-color:rgb(77,135,165);font:12pt '宋体';color: white;};",35,35);
    table_single::GetInstance()->TableWidgetInit(ui->tableWidget_agv,14,"QHeaderView::section{background-color:rgb(77,135,165);font:12pt '宋体';color: white;};",35,35);
    connect(ui->tableWidget,&QTableWidget::cellClicked,this,&MainDesktop::SlotsetCurrentItem);
    connect(ui->tableWidget_agv,&QTableWidget::cellClicked,this,&MainDesktop::SlotsetCurrentItem_2);

    ui->tabWidget->setCurrentIndex(0);
    currentlabel = new QPushButton;
    connect(currentlabel,&QPushButton::clicked,this,&MainDesktop::ON_Click);
    currentlabel->setText("    ");
    currentlabel->setMinimumSize(30,25);
    IconHelper::Instance()->setIcon(currentlabel, 0xf02c, 15);
    currentlabel->setToolTip("当容器到位后，机器人不去取货时可先解绑，再重新绑定");
    ui->tabWidget->setCornerWidget(currentlabel,Qt::TopRightCorner);

    CarStautsMap.insert(0,"未知");
    CarStautsMap.insert(1,"满车架");
    CarStautsMap.insert(2,"空车架");

//    ui->widget_2->setVisible(false);
    ui->taskStatusBox_AGV->setVisible(false);
    ui->checkBox_Edite_2->setVisible(false);
    ui->Button_Init->setVisible(false);
}

void MainDesktop::tableWidget_Show()
{
    //解决显示卡顿问题:  https://blog.csdn.net/u014746838/article/details/102642083
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    QStringList comBoxlist;
    QList<RW_Excel> ExcelList=TableWidget();
    table_single::GetInstance()->UP_TableWidget(ui->tableWidget,ExcelList,comBoxlist,0);
    if(ExcelList.isEmpty()){
        ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//列宽根据表格大小自适应
        return;
    }

    /**
     * 赖俊龙
     * 设置任务信息表格显示自适应
     */
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//列宽根据表格大小自适应
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(9,QHeaderView::ResizeToContents);
//  ui->tableWidget->sortItems(6, Qt::AscendingOrder);// 对 n 列排序, 默认升序

}

//AGV状态列表显示
QList<RW_Excel> MainDesktop::TableWidget()
{
    QList<RW_Excel> ExcelList;
    QList<RW_Excel> ExcelList0;
    QList<RW_Excel> ExcelList1;
    QList<RW_Excel> ExcelList2;
    QList<RW_Excel> ExcelList3;
    QMap<int, SAPExcelInfo>::const_iterator iter= seletSAPExcelInfoTask.begin();
    while (iter!=seletSAPExcelInfoTask.end()){
        if(iter!=nullptr){
            if(iter.value().taskStatus<taskFnish){
                int incount=0;
                RW_Excel RW_ExcelItem;
                RW_ExcelItem.ExcelB=iter.value().taskType;                                                        // 任务类型
                RW_ExcelItem.ExcelC=iter.value().taskTypeDesc;                                                    // 任务类型描述
                RW_ExcelItem.ExcelD=iter.value().taskId;                                                          // 任务编码
                RW_ExcelItem.ExcelE=iter.value().load;                                                            // 起始库位
                RW_ExcelItem.ExcelF=iter.value().unload;                                                          // 目标库位
                RW_ExcelItem.ExcelG=iter.value().agvNum;                                                          // AGV 编号
                RW_ExcelItem.ExcelH=iter.value().taskStatusDesc+"-"+QString::number(iter.value().taskStatus);     // 任务状态注释
                RW_ExcelItem.ExcelI=QString::number(iter.value().SAPTaskIndex);                                   // 序列号
                RW_ExcelItem.ExcelJ=iter.value().creatTimer.toString("yyyy-MM-dd hh:mm:ss");                      // 创建时间
                RW_ExcelItem.checked=iter.value().checked;                                                        // 选中状态

                //二楼正在运行
                if(incount==0 && (iter.value().taskStatus>0 && iter.value().taskStatus<100)){
                    incount=1;
                    RW_ExcelItem.corlor=2;// 灰色
                    ExcelList0.append(RW_ExcelItem);
                }
                if(incount==0 && (iter.value().taskStatus>9 && iter.value().taskStatus<15)){
                    incount=1;
//                    RW_ExcelItem.corlor=3;// 棕色
                    ExcelList1.append(RW_ExcelItem);
                }

                if(incount==0 && iter.value().taskStatus==0){
                    incount=1;
                    RW_ExcelItem.corlor=0;// 白色
                    ExcelList2.append(RW_ExcelItem);
                }

                if(incount==0){
                    incount=1;
                    RW_ExcelItem.corlor=0;// 白色
                    ExcelList3.append(RW_ExcelItem);
                }

            }
        }else{
            return ExcelList;
        }
        iter++;
    }

    ExcelList=ExcelList0+ExcelList1+ExcelList2+ExcelList3;
    for(int i=0;i<ExcelList.size();i++){
        ExcelList[i].ExcelA=QString::number(i+1);
    }
    return ExcelList;
}

void MainDesktop::tableWidget_Show_agv()
{
    //解决显示卡顿问题:  https://blog.csdn.net/u014746838/article/details/102642083
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    QStringList comBoxlist;
    QList<RW_Excel> ExcelList=TableWidget_agv();
    table_single::GetInstance()->UP_TableWidget(ui->tableWidget_agv,ExcelList,comBoxlist,0);
    if(ExcelList.isEmpty()){
        ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//列宽根据表格大小自适应
        return;
    }

    /**
     * 赖俊龙
     * 设置 AGV 信息列表显示自适应
     */
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//列宽根据表格大小自适应
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(0,QHeaderView::ResizeToContents);
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(1,QHeaderView::ResizeToContents);
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(2,QHeaderView::ResizeToContents);
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(3,QHeaderView::ResizeToContents);
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(5,QHeaderView::ResizeToContents);
    ui->tableWidget_agv->horizontalHeader()->setSectionResizeMode(10,QHeaderView::ResizeToContents);

}

QList<RW_Excel> MainDesktop::TableWidget_agv()
{
    QList<RW_Excel> ExcelList;
    QList<RW_Excel> ExcelList0;
    QMap<QString,AGVCurrentTask>::iterator iter;
    foreach(AGVCurrentTask iter,AGVCurrentTaskMap.values()){
        int incount=0;
        RW_Excel RW_ExcelItem;
        RW_ExcelItem.ExcelA=QString::number(iter.AGVId);            // AGV 编号
        RW_ExcelItem.ExcelB=iter.AGVIP;                             // AGV IP 地址
        RW_ExcelItem.ExcelC=iter.taskId;                            // AGV 主任务编码
        RW_ExcelItem.ExcelD=iter.unitId;                            // AGV 子任务编码

        if ( iter.taskType == 1 )
        {
            RW_ExcelItem.ExcelE="Move";                             // AGV 任务类型
        }else if ( iter.taskType == 3 )
        {
            RW_ExcelItem.ExcelE="Action";                           // AGV 任务类型
        }else
        {
            RW_ExcelItem.ExcelE=tr("其他");                          // AGV 任务类型
        }

        if (iter.status == 0 && !iter.unitId.isEmpty())
        {
            RW_ExcelItem.ExcelF=QString::number(iter.status) + tr("-等待执行");           // 任务状态
        }else if (iter.status > 0 && iter.status < 100 && !iter.unitId.isEmpty())
        {
            RW_ExcelItem.ExcelF=QString::number(iter.status) + tr("-正在执行");           // 任务状态
        }else if (iter.status == 100 && !iter.unitId.isEmpty())
        {
            RW_ExcelItem.ExcelF=QString::number(iter.status) + tr("-执行完成");           // 任务状态
        }else if (iter.unitId.isEmpty())
        {
            RW_ExcelItem.ExcelF=tr("100-执行完成");                                       // 任务状态
        }

        if ( iter.AGVState == 0 )
        {
            RW_ExcelItem.ExcelG=tr("空闲");                              // AGV 状态
        }else if ( iter.AGVState == 1 )
        {
            RW_ExcelItem.ExcelG=tr("正在运行");                           // AGV 状态
        }else if ( iter.AGVState == 2 )
        {
            RW_ExcelItem.ExcelG=tr("异常");                              // AGV 状态
        }else if ( iter.AGVState == 3 )
        {
            RW_ExcelItem.ExcelG=tr("正在充电");                           // AGV 状态
        }else if ( iter.AGVState == -1 )
        {
            RW_ExcelItem.ExcelG=tr("掉线");                              // AGV 状态
        }else if ( iter.AGVState == -2 )
        {
            RW_ExcelItem.ExcelG=tr("未重定位");                           // AGV 状态
        }else
        {
            RW_ExcelItem.ExcelG=tr("其他");                              // AGV 状态
        }

        if(!iter.unitId.isEmpty() && iter.unitId.split("-").size() > 1)
        {
            RW_ExcelItem.ExcelH=iter.unitId.split("-").at(1);           // 序列编码
        }

        RW_ExcelItem.ExcelI=QString::number(iter.currentStation);       // AGV当前站点
        RW_ExcelItem.ExcelJ=QString::number(iter.batteryLevel);         // AGV 电量，百分比
        RW_ExcelItem.ExcelK=iter.agvPosition;                           // AGV位置信息(x,y)
        RW_ExcelItem.ExcelL=QString::number(iter.errorCode);            // 错误信息描述
        RW_ExcelItem.checked=iter.checked;                              // 选中状态

        if(incount==0 ){
            incount=1;
            RW_ExcelItem.corlor=0;
            if(!iter.isOnline || iter.AGVState == -1){
                RW_ExcelItem.corlor=4;// 红色
                RW_ExcelItem.ExcelG=tr("掉线");                          // AGV 状态
                RW_ExcelItem.ExcelL=tr("掉线");                          // 错误信息描述
            }else{
                if(iter.errorCode!=0){
                    RW_ExcelItem.corlor=4;// 红色
                }if(iter.batteryLevel<30){
                    RW_ExcelItem.corlor=3;// 棕色
                }

            }
            ExcelList.append(RW_ExcelItem);
        }

    }
    return ExcelList;
}

void MainDesktop::CancelInit(QString taskType)
{
    if(taskType=="task"){
        SAPExcelInfo SAPExcelInfoI;
        seletSAPExcelInfoI=SAPExcelInfoI;
        QMap<int, SAPExcelInfo>::iterator iter= seletSAPExcelInfoTask.begin();
        while (iter!=seletSAPExcelInfoTask.end()){
            iter.value().checked=0;
            iter++;
        }
        tableWidget_Show();//tableWidget 更新显示
    }if(taskType=="AGV"){
        AGVCurrentTask AGVCurrentTaskI_;
        AGVCurrentTaskI=AGVCurrentTaskI_;
    }
}

bool MainDesktop::setAGVCurrentTaskMap_Status(QMap<QString, AGVCurrentTask> AGVCurrentTaskMap)
{
    //更新AGV状态信息
    bool update=true;
    connectBuilder build(ASMORDERDBSTR);
    QSqlDatabase sqlDatabase =  build.getOpenDatabase();
    QSqlQuery sqlQuery(sqlDatabase);
    QMap<QString, AGVCurrentTask>::const_iterator iter=AGVCurrentTaskMap.begin();
    while (iter!=AGVCurrentTaskMap.end()) {
        if(iter!=nullptr){
            sqlQuery.prepare("UPDATE [dbo].[AGVCurrentTask] SET [taskId]=:taskId,[lastTaskId]=:lastTaskId,"
                             "[taskType]=:taskType,[msg]=:msg,[status]=:status,[SAPTaskIndex]=:SAPTaskIndex,"
                             "[station]=:station,[agvStation]=:agvStation,"
                             "[agvPosition]=:agvPosition,[AGVState]=:AGVState,"
                             "[batteryLevel]=:batteryLevel,[errorCode]=:errorCode,[currentStation]=:currentStation "
                             "WHERE ([AGVIP]=:AGVIP);");

            sqlQuery.addBindValue(iter.value().taskId);
            sqlQuery.addBindValue(iter.value().lastTaskId);
            sqlQuery.addBindValue(iter.value().taskType);
            sqlQuery.addBindValue(iter.value().msg);
            sqlQuery.addBindValue(iter.value().status);
            sqlQuery.addBindValue(iter.value().SAPTaskIndex);
            sqlQuery.addBindValue(iter.value().station);
            sqlQuery.addBindValue(iter.value().currentNode);
            sqlQuery.addBindValue(iter.value().agvPosition);
            sqlQuery.addBindValue(iter.value().AGVState);
            sqlQuery.addBindValue(iter.value().batteryLevel);
            sqlQuery.addBindValue(iter.value().errorCode);
            sqlQuery.addBindValue(iter.value().currentStation);
            sqlQuery.addBindValue(iter.value().AGVIP);

            if(sqlQuery.exec()){
//                qDebug()<<"set codeDesc S---->AGVIP:"<<iter.value().AGVIP<<" Action_agv:"<<iter.value().Action_agv
//                       <<" taskType:"<<iter.value().taskType<<" SAPTaskIndex:"<<iter.value().SAPTaskIndex;
            }else {
                update= false;
//                qDebug()<<"set codeDesc ---->AGVIP:"<<iter.value().AGVIP<<" Action_agv:"<<iter.value().Action_agv
//                       <<" taskType:"<<iter.value().taskType<<" SAPTaskIndex:"<<iter.value().SAPTaskIndex;
            }
        }else{
             return false;
        }
        iter++;
    }

    return update;

}

void MainDesktop::ON_MainDesktopTimer()
{
    if(Desktop){
        Desktop=false;
        TableWidgetcount++;
        if(ServerInitItem.UserInfoList.isEmpty()){
            /************** 基础信息赋值 *******************/
            allServerInit ALLServerInitItem=queryServer::getInstance()->getCurrentServerInitItem();
            ServerInitItem=ALLServerInitItem.ServerInitItem;
        }

        switch (TableWidgetcount%remainder)
        {
            case 0:
            {
                if(seletSAPExcelInfoI.SAPTaskIndex==0){
                    seletSAPExcelInfoTask=ESS_Single::GetInstance()->getCurrentSAPExcelInfoTask();
                    tableWidget_Show();                             //tableWidget 更新显示
                }else{
                    qint64 statusTimers = statusTimer.secsTo(QDateTime::currentDateTime());
                    if(statusTimers>=5){
                        SAPExcelInfo SAPExcelInfoI;
                        seletSAPExcelInfoI=SAPExcelInfoI;
                    }
                }
            }
                break;
            case 2:
            {
                setAGVCurrentTaskMap_Status(AGVCurrentTaskMap);
            }
                break;
            case 4:
            {
                if(AGVCurrentTaskI.AGVIP==""){
                    tableWidget_Show_agv();
                }else{
                    qint64 statusTimers = statusTimer_agv.secsTo(QDateTime::currentDateTime());
                    if(statusTimers>=5){
                        AGVCurrentTask AGVCurrentTask_;
                        AGVCurrentTaskI=AGVCurrentTask_;
                    }
                }
            }
                break;
            default:
                break;
        }

        Desktop=true;
    }
    if(TableWidgetcount>10000){TableWidgetcount=0;}
}

void MainDesktop::SlotsetCurrentItem(int row, int column)
{
    SAPExcelInfo SAPExcelInfoI;
    seletSAPExcelInfoI=SAPExcelInfoI;
    int SAPTaskIndex=ui->tableWidget->item(row,8)->text().trimmed().toInt();
    QMap<int, SAPExcelInfo>::iterator iter= seletSAPExcelInfoTask.begin();
    while (iter !=seletSAPExcelInfoTask.end()) {
        if(iter.value().SAPTaskIndex==SAPTaskIndex){
            if(iter.value().checked==0){//选中
                iter.value().checked=1;
                seletSAPExcelInfoI=iter.value();
                ui->widget->setVisible(true);
                statusTimer=QDateTime::currentDateTime();
            }else {
                iter.value().checked=0;
            }
        }else{
            iter.value().checked=0;
        }
        iter++;
    }

    tableWidget_Show();//tableWidget 更新显示
}

void MainDesktop::SlotsetCurrentItem_2(int row, int column)
{
    AGVCurrentTask AGVCurrentTaskI_;
    AGVCurrentTaskI=AGVCurrentTaskI_;
    QString AGVIP=ui->tableWidget_agv->item(row,1)->text().trimmed();
    QMap<QString, AGVCurrentTask>::iterator iter= AGVCurrentTaskMap.begin();
    while (iter !=AGVCurrentTaskMap.end()) {
        if(iter.value().AGVIP==AGVIP){
            if(iter.value().checked==0){//选中
                iter.value().checked=1;
                AGVCurrentTaskI=iter.value();
                statusTimer_agv=QDateTime::currentDateTime();
            }else {
                iter.value().checked=0;
            }
        }else{
            iter.value().checked=0;
        }
        iter++;
    }
    tableWidget_Show_agv();

}

void MainDesktop::slotAGVCurrentTaskMap(QMap<QString, AGVCurrentTask> AGVCurrentTaskMapI,bool BatteryLevel)
{
    currentBatteryLevel=BatteryLevel;
    AGVCurrentTaskMap=AGVCurrentTaskMapI;
}

void MainDesktop::ON_Click()
{
    if(ui->widget->isVisible()){
        ui->widget->setVisible(false);
    }else{
        ui->widget->setVisible(true);
    }
}

void MainDesktop::ON_WriteModbusI(int address, quint16 value)
{
    emit sig_WriteModbusII(address, value);
}

void MainDesktop::ON_UpdateStation(QString Station, int stationStatus, QString scanCode)
{
    emit sig_UpdateStationI(Station, stationStatus, scanCode);
}

void MainDesktop::ON_Translate()
{
    qApp->installTranslator(&ESS_Single::GetInstance()->trans);
    ui->retranslateUi(this);

    // 判断任务表格是否有数据
    if (ui->tableWidget->rowCount() > 0) {
        //刷新任务表格
        tableWidget_Show();
    }

    // 判断AGV信息表格是否有数据
    if (ui->tableWidget_agv->rowCount() > 0) {
        //刷新AGV信息表格
        tableWidget_Show_agv();
    }

    //主界面翻译信号
    emit sig_Translate();
}

void MainDesktop::ON_TextDisplay(QString Text)
{

    if(Text.isEmpty())
    {
        ui->label_test->setText(tr("任务状态描述：正常"));
    }else
    {
        ui->label_test->setText(tr("任务状态描述：%1").arg(Text));
//        ui->label_test->setText(Text);
    }

}

void MainDesktop::on_Delete_Button_clicked()
{
    if(ui->checkBox_Edite->isChecked()){
        if(seletSAPExcelInfoI.SAPTaskIndex>0){

            if(queryServer::getInstance()->SetMessagebox(tr("是否确认异常完成任务？")))
            {
                seletSAPExcelInfoI.taskStatus=taskFnish;
                emit sig_deleteSAPExcelInfoTask(seletSAPExcelInfoI);
                // 取消勾选
                ui->checkBox_Edite->setChecked(false);
            }

        }else{
            queryServer::getInstance()->SetMessagebox(tr("请选择异常完成的任务"));
        }
        CancelInit("task");
    }else{
        queryServer::getInstance()->SetMessagebox(tr("请点击勾选选项"));
    }
}

void MainDesktop::on_taskStatusBox_AGV_currentTextChanged(const QString &arg1)
{
    if(ui->taskStatusBox_AGV->currentIndex()!=0){
        if(AGVCurrentTaskI.AGVIP!=""){
            ESS_Request ESS_RequestI;
            if(queryServer::getInstance()->SetMessagebox("是否执行当前AGV工作站指令?")){
                 bool sendTask=false;
                 if(sendTask){
                     //手动更新AGV当前动作指令状态
                     //emit sig_AGVCurrentTaskAction(AGVCurrentTaskI->AGVIP, "Type", Action);
                     qDebug()<<"手动更新AGV当前动作指令状态--sig0->AGVIP:"<<AGVCurrentTaskI.AGVIP;
                 }else{
                    queryServer::getInstance()->SetMessagebox("当前任务无法执行->:"+arg1);
                 }
            }
        }else{
            queryServer::getInstance()->SetMessagebox("请选择需要更改项");
        }
        ui->taskStatusBox_AGV->setCurrentIndex(0);
        CancelInit("AGV");
    }
}

void MainDesktop::on_Button_Init_clicked()
{
    if(ui->checkBox_Edite_2->isChecked()){
        if(queryServer::getInstance()->SetMessagebox("是否初始化当前AGV?")){
            if(AGVCurrentTaskI.AGVIP!=""){
                //手动更新AGV当前动作指令状态
                emit sig_AGVCurrentTaskAction(AGVCurrentTaskI.AGVIP,"Type",100);
                qDebug()<<"手动更新AGV当前动作指令状态--sig1->AGVIP:"<<AGVCurrentTaskI.AGVIP;
            }else {
                queryServer::getInstance()->SetMessagebox("请选择需要更改项");
            }
        }
        CancelInit("AGV");
    }
}

void MainDesktop::on_AgvExecute_re_clicked()
{

    if (queryServer::getInstance()->SetMessagebox(tr("是否确认一键复位？")))
    {
        int _agvId = 0;
        SAPExcelInfo SAPExcelInfoI;
        seletSAPExcelInfoI=SAPExcelInfoI;

        // 获取一键复位 AGV
        if (ui->taskStatusBox_ESS_2->currentIndex() == 0)
        {
            _agvId = 1;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 1)
        {
            _agvId = 2;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 2)
        {
            _agvId = 3;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 3)
        {
            _agvId = 4;
        }


        if (_agvId > 0)
        {
            // 查找当前 AGV 对应任务
            foreach (SAPExcelInfo iter, seletSAPExcelInfoTask.values())
            {

                if (iter.agvNum == QString::number(_agvId))
                {
                    seletSAPExcelInfoI = iter;
                    seletSAPExcelInfoI.taskStatus=taskFnish;
                }

            }

            if (seletSAPExcelInfoI.SAPTaskIndex > 0)
            {
                emit sig_deleteSAPExcelInfoTask(seletSAPExcelInfoI);
            }else
            {
                //取消指定AGV全部任务指令
                ESS_Single::GetInstance()->setAgvCancelTask(_agvId);
            }

            //清除指定AGV管制
            ESS_Single::GetInstance()->setAgvClearTraffControlTask(_agvId);
        }

        CancelInit("task");

        queryServer::getInstance()->SetMessagebox(tr("一键复位成功！！！"));

        qDebug()<<"on_AgvExecute_re_clicked--agvId:"<<_agvId;
    }

}



void MainDesktop::on_taskStatusBox_ESS_currentIndexChanged(int index)
{
    if(index==0){
        agvTaskBool=0;
    }if(index==1){
        agvTaskBool=1;
    }
    emit sigAgvTaskBool(agvTaskBool); //AGV任务启动状态
}

void MainDesktop::on_AgvExecute_re_2_clicked()
{

    if (queryServer::getInstance()->SetMessagebox(tr("是否确认清除管制？")))
    {
        int _agvId = 0;

        // 获取一键复位 AGV
        if (ui->taskStatusBox_ESS_2->currentIndex() == 0)
        {
            _agvId = 1;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 1)
        {
            _agvId = 2;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 2)
        {
            _agvId = 3;

        }else if (ui->taskStatusBox_ESS_2->currentIndex() == 3)
        {
            _agvId = 4;
        }


        if (_agvId > 0)
        {
            //清除指定AGV管制
            ESS_Single::GetInstance()->setAgvClearTraffControlTask(_agvId);
        }

        CancelInit("task");

        queryServer::getInstance()->SetMessagebox(tr("清除管制成功！！！"));

        qDebug()<<"on_AgvExecute_re_2_clicked--agvId:"<<_agvId;
    }

}
